# voice_checker.py - 检查声音文件内容
import torch
import os

def inspect_voice_file(file_path):
    """详细检查声音文件内容"""
    if not os.path.exists(file_path):
        print(f"文件不存在: {file_path}")
        return None
    
    try:
        print(f"检查文件: {file_path}")
        file_size = os.path.getsize(file_path)
        print(f"文件大小: {file_size} 字节")
        
        # 尝试不同的加载方式
        print("\n1. 尝试使用 weights_only=False 加载...")
        data = torch.load(file_path, map_location='cpu', weights_only=False)
        print("✓ 使用 weights_only=False 加载成功")
        
        print(f"数据类型: {type(data)}")
        
        if isinstance(data, torch.Tensor):
            print(f"张量形状: {data.shape}")
            print(f"张量类型: {data.dtype}")
            print(f"张量值范围: [{data.min():.4f}, {data.max():.4f}]")
        elif isinstance(data, dict):
            print(f"字典键: {list(data.keys())}")
            for key, value in data.items():
                if isinstance(value, torch.Tensor):
                    print(f"  {key}: 张量 {value.shape} {value.dtype}")
                else:
                    print(f"  {key}: {type(value)}")
        else:
            print(f"内容类型: {type(data)}")
            print(f"内容: {data}")
        
        return data
        
    except Exception as e:
        print(f"❌ 检查文件失败: {e}")
        return None

# 使用检查工具
if __name__ == "__main__":
    voice_file = "D:\\BIANCHENG\\script\\exercise\\py\\kkr\\82M\\kokoro-v1_1-zh.pth"
    data = inspect_voice_file(voice_file)